package com.jagochan.imchat.module.common.interceptor;

import lombok.Data;

/**
 * ThreadLocal线程共享对象
 */
public class ContextInfoHolder {
    private static final ThreadLocal<ContextInfoDTO> THREAD_LOCAL = new ThreadLocal<>();

    public static void set(Long uid, String ip) {
        ContextInfoDTO contextInfoDTO = new ContextInfoDTO();
        contextInfoDTO.setUid(uid);
        contextInfoDTO.setIp(ip);
        THREAD_LOCAL.set(contextInfoDTO);
    }

    public static ContextInfoDTO get() {
        return THREAD_LOCAL.get();
    }

    public static void remove() {
        THREAD_LOCAL.remove();
    }

    @Data
    public static class ContextInfoDTO {
        private Long uid;
        private String ip;
    }

}
